#ifndef CKNXCONTROL_H
#define CKNXCONTROL_H

#include <QThread>
#include "ttg_ips/cttgipsconnector.h"
#include "audio/audio_control.h"

class CExecStruct: public QObject
{
    Q_OBJECT
public:
    explicit CExecStruct(QObject *parent = 0);
    QString address;
    DATA_TYPE type;
    QByteArray data;
};

class CKnxExecThread : public QThread
{
    Q_OBJECT
public:
    explicit CKnxExecThread(QThread *parent = 0);
    QList<CExecStruct *> execList;
    CTTGIpsConnector *ttgConnector;

signals:
    void s_knxWrite(QByteArray addr2bytes,int,QByteArray);
    void s_knxRead(QByteArray addr2bytes);

protected:
    void run();
};

class CKnxControl : public QObject
{
    Q_OBJECT
public:
    explicit CKnxControl(QObject *parent = 0);
    //对于实际的设备来说，它具有位置信息
    QString _id,_name,_icon,_exp,_action,_send,_feedback,_state_value,
        _floor,_location,_area,_device_name,_selection;

    QString _status_true, _status_false,_min_value,_max_value;

    unsigned char _data_buf[64];
    void *cntDelegate;

    static int parseNumberFromString(QString num);
    static QString foundKeyFromExp(QString exp,QString key);
    virtual void parseExp(QString exp);
    virtual void parseSelection(QString selection);

    void parseZone(QString zone);
    virtual void execDeviceAction(QString action,QString value,QString pre_unit) = 0;

    virtual void setKnxObject(void *Json_DEVICE_OBJECT) = 0;
    virtual void execKnxAction(QString action,QString value) = 0;
    virtual void readKnxAction() = 0;
    virtual QString valueCheck(QString action,QString value);
    virtual QString actionFromStatus(QString address,QString value) = 0;

signals:
    void s_KnxWrite(QString address,int data_type,QByteArray value);
    void s_KnxRead(QString address,int data_type);

};

#endif // CKNXCONTROL_H
